package com.example.management.controller;

import com.example.management.pojo.Student;
import com.example.management.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.List;

@Api(tags = "学生")
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("所有学生信息")
    @PostMapping("getAll")
    public List<Student> getAll() {
        return studentService.getAllStudent();
    }

    @ApiOperation("通过学号查询学生")
    @PostMapping("getStudentByNum")
    public Student getStudent(@RequestParam Long number) {
        return studentService.getStudent(number);
    }

    @ApiOperation("通过宿舍牌号查询学生")
    @PostMapping("getSomeStudentByTag")
    public List<Student> getSomeStudent(@RequestParam String buildingTag, @RequestParam String tag) {
        return studentService.getSomeStudent(buildingTag, tag);
    }

    @ApiOperation("通过专业和班级查询学生")
    @PostMapping("getSomeStudentByMajor")
    public List<Student> getStudentByMajorAndClass(@RequestParam String major, Integer classes) {
        return studentService.getStudentByMajorAndClass(major, classes);
    }

    @ApiOperation("通过学号删除指定账号")
    @PostMapping("delete")
    public String deleteStudent(@RequestParam Long num) {
        Student student = new Student();
        student.setNumber(num);
        return studentService.deleteStudent(student);
    }

    @ApiOperation("添加账户")
    @PostMapping("add")
    public String addStudent(@RequestParam Date birth, @RequestParam Integer classes, @RequestParam Integer dormitoryNumber,
                             @RequestParam String major, @RequestParam String name,
                             @RequestParam Long number, @RequestParam Long phone, @RequestParam String sex) {
        Student student = new Student(number, sex, name, birth, major, classes, phone, dormitoryNumber);
        return studentService.addStudent(student);
    }
}
